<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-10-18
 * Time: 15:40
 */

namespace app\mobileweb\controller;


use app\src\base\utils\BoyeService;
use think\Session;
use think\Controller;

/**
 *
 * Index作为登录接口
 *
 */
class Product extends Webview{
    public function _initialize()
    {
        $this->needValid =true;  //不需要验证用户密码
        parent::_initialize();
    }

    /**
     * 商品搜索关键词接口
     * @author hebidu <email:346551990@qq.com>
     */
    public function searchKeywords(){
        $keyword=$this->_post('keyword','');

        $device_token = $this->_post('device_token','');
        $device_type  = 'pc';
        $data = array(
            "keyword" => $keyword,
        );
        $t= array(
            'api_ver'  => 100,
            'notify_id'=> time(),
            'alg'      => 'md5',
            'device_token'=>$device_token,
            'device_type'=>$device_type,
            'type'	   => 'BY_Product_searchKeywords'
        );

        $data = array_merge($t, $data);
        $service=new Boyeservice();
        $fanhui=$service->callRemote('',$data,false);
        $this->assign('data',$fanhui['info']);
        //dump($fanhui['info']);
        return $this->fetch();

    }

    /**
     * 商品搜索关键词接口
     * @author hebidu <email:346551990@qq.com>
     */
    public function detail(){
        $pid=$this->_get('pid','');
        $device_token = $this->_post('device_token','');
        $device_type  = 'pc';
        $data = array(
            "id" => $pid,
        );
        $t= array(
            'api_ver'  => 102,
            'notify_id'=> time(),
            'alg'      => 'md5',
            'device_token'=>$device_token,
            'device_type'=>$device_type,
            'type'	   => 'By_Product_detail'
        );

        $data = array_merge($t, $data);
        $service=new Boyeservice();
        $fanhui=$service->callRemote('',$data,false);
        $this->assign('data',$fanhui['info']);
        $this->assign('img',$fanhui['info']['carousel_images']);
        //dump($fanhui['info']);
        return $this->fetch();

    }




    /**
     * 商品搜索分页接口
     * @author hebidu <email:346551990@qq.com>
     */
    public function search(){
        $vt= array(
            'api_ver'  => 100,
            'notify_id'=> time(),
            'alg'      => 'md5',
            'type'	   => 'BY_Category_queryMainCategory'
        );
        $service=new Boyeservice();
        $alist=$service->callRemote('',$vt,false);
        $this->assign('alist',$alist['info']);

        if(IS_POST){
            $cate_id=$this->_post('cate_id','');
            $this->assign('cate_id',$cate_id);
            $ot= array(
                'api_ver'  => 100,
                'cate_id'=>$cate_id,
                'notify_id'=> time(),
                'alg'      => 'md5',
                'type'	   => 'BY_Category_querySubCategory'
            );
            $service=new Boyeservice();
            $blist=$service->callRemote('',$ot,false);
            $this->assign('blist',$blist['info']);

            $sub_id=$this->_post('sub_id','');
            $this->assign('sub_id',$sub_id);
            if($sub_id){
                $uid=$this->getuid();
                $keyword=$this->_post('keyword','');
                $device_type  = 'pc';
                $data = array(
                    'uid'=>$uid,
                    'cate_id'=>$sub_id,
                    "keyword" => $keyword,
                    'page_index'=>$this->_post('p',1)
                );
                $t= array(
                    'api_ver'  => 101,
                    'notify_id'=> time(),
                    'alg'      => 'md5',
                    'device_type'=>$device_type,
                    'type'	   => 'BY_Product_search'
                );

                $data = array_merge($t, $data);
                $service=new Boyeservice();
                $fanhui=$service->callRemote('',$data,false);
                $this->assign('data',$fanhui['info']['list']);
            }else{
                $this->assign('data','');
            }
            return $this->fetch();
        }else{
            $this->assign('cate_id','0');
            $this->assign('blist','');
            $this->assign('data','');
            return $this->fetch();
        }
    }

}